//
//  ZXLAPI.m
//  ZXLSign
//
//  Created by awh on 2020/11/8.
//

#import "ZXLAPI.h"
//#import "AFNetworking.h"
//#import "ZXLSignTools.h"
//#import "SignConfig.h"
@interface SceneFactory ()<SceneProtocol>

@end
@implementation ZXLAPI
-(instancetype)initConfig:(ZXLConfig*)config{
    self=[self init];
    if (self) {
        
    }
    return self;
}
-(void)setManager:(AFHTTPSessionManager *)manager SignWith:(ZXLAPISignData *)data{
    id stringToSign = [self StructuralData:data];
    [manager.requestSerializer setValue:@"" forHTTPHeaderField:@""];
}

-(id)StructuralData:(ZXLAPISignData *)data{
    NSMutableURLRequest *request =[data.requestType isEqualToString:@"GET"]? [[AFHTTPRequestSerializer  serializer] requestWithMethod:data.requestType URLString:data.URL parameters:data.body error:nil]:[[AFJSONRequestSerializer  serializer] requestWithMethod:data.requestType URLString:data.URL parameters:data.body error:nil];
    
    NSString * strTosign;
    NSString * base641;
    if ([data.requestType isEqualToString:@"GET"]) {
        NSString *sortQuery = [ZXLSignTools getStringWithDic:(NSMutableDictionary*)data.body];
        strTosign = [NSString stringWithFormat:@"%@\\n%@&%@\\n%@\\n%@\\n%@\\n%@\\n%@",request.URL.path,sortQuery,[self currentTimestamp],[self getNonce],[ZXLUserInfo getUserInfo].version,APPKey,SIGN_SK];
    }
   
  //    request.URL.query
  //    request.URL.host;
  //    request.HTTPBody;
    
    NSLog(@"++++%@",request);
    //加密;
    [self getMessageDigestString:@""];
    
    
    
    /*
    NSString *receiveStr = [[NSString alloc]initWithData:request.HTTPBody encoding:NSUTF8StringEncoding];

    NSLog(@"字符串 %@",receiveStr);
    
    NSData * data = [receiveStr dataUsingEncoding:NSUTF8StringEncoding];

    NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
     NSLog(@"字店 =%@",jsonDict);
     */
    return @"";
}

-(SignResult *)getSignWith:(ZXLSignData *)data
{
//    id  stringToSign = [self StructuralData:data];
//    switch (self.sceneConfig.encryType) {
//        case SecurityEncryptTypeAES:
//        {
//            [ZXLSignToolAES AESEncrypt:stringToSign key:@"" keySize:KeySizeAES128];
//        }
//            break;
//        case SecurityEncryptTypeDES:
//            break;
//            
//        case SecurityEncryptTypeRSA:
//            break;
//        default:
//            break;
//    }
//    
    return [SignResult new];
}

@end
